package govenor.status;

import java.io.StringReader;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;

import tcp.heartbeat.HeartbeatHandler;
import govenor.overwatch.OverWatcher;
import handlers.DataCallBack;

public class StatusManager implements DataCallBack{

	private OverWatcher watcher;
	
	public static final int STATUS_CHECK_PERIOD = 20;
	public static final int NUMBER_OF_STATUS_THREADS = 4;
	private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(NUMBER_OF_STATUS_THREADS);
	
	public StatusManager(OverWatcher watcher){
		this.watcher = watcher;
		scheduler.scheduleAtFixedRate(new StatusHandler(this), 10, STATUS_CHECK_PERIOD, TimeUnit.SECONDS);
	
	}
	public List getWatchedFileStores(){
		return this.watcher.getListOfWatchedElements(null);
	}
	public void dataResponse(String serverId, String data) {
		StringReader reader = new StringReader(data);
		Model model = ModelFactory.createDefaultModel() ;
		model.read(reader,"");
		this.watcher.updateStatusFromModel(serverId,model);
		
	}
	
	
	
}
